/**
 * @param {WebMail} oWebMail
 */
function WebMailLoginScreen(oWebMail)
{
	this.webmail = oWebMail;
	this.screenObj = $('#login-screen');
}

WebMailLoginScreen.prototype =
{
	initScreen: function ()
	{
		var obj = this;
		$('#sIncLogin', this.screenObj).blur(function (){
			var sLoginValue = $(this).val();
			if (0 < sLoginValue.length)
			{
				var sIncHost = $('#sIncHost', this.screenObj);
				var iIntPort = $('#iIntPort', this.screenObj);
				var aEmail = sLoginValue.split('@');

				if (0 === sIncHost.val().length && 1 < aEmail.length)
				{
					sIncHost.val(
						('undefined' !== typeof(obj.webmail.domains[aEmail[1].toLowerCase()]))
							?  obj.webmail.domains[aEmail[1].toLowerCase()][0] : aEmail[1]
					);
				}
				if (0 === iIntPort.val().length && 1 < aEmail.length)
				{
					if (1 < aEmail.length)
					{
						iIntPort.val(
							('undefined' !== typeof(obj.webmail.domains[aEmail[1].toLowerCase()]))
								?  obj.webmail.domains[aEmail[1].toLowerCase()][1] : 143
						);
					}
				}
			}
		});

		$('#login-form', this.screenObj).submit(function (event) {
			 obj.webmail.ajaxRequest('Login', {
				'sIncLogin': $('#sIncLogin', this.screenObj).val(),
				'sIncPassword': $('#sIncPassword', this.screenObj).val(),
				'sIncHost': $('#sIncHost', this.screenObj).val(),
				'iIntPort': $('#iIntPort', this.screenObj).val()
			});
			event.preventDefault();
		});

		$(this.screenObj).removeClass('hide');
	},

	/**
	 * @param {string} sAction
	 * @param {object} oItem
	 * @return {void}
	 */
	buildResponseItem: function (sAction, oItem)
	{
		if ('Login' === sAction && true === oItem.Response)
		{
			this.webmail.goToHash('');
			location.reload(true);
		}
	},

	/**
	 * @param {string} sHash
	 * @return {bool}
	 */
	buildHash: function (sHash)
	{
		return true;
	}
}
